﻿using System;
using System.Linq;
using System.Text;
using Crossroad.Utils.Extensions;
using SqlSugar;

namespace Crossroad.System.Widget.Model
{
    ///<summary>
    ///通知公告
    ///</summary>
    [SugarTable("widget_notice")]
    public partial class Notice : ModelContext
    {
        public Notice()
        {
            LoadDefVal();
        }
        public Notice(bool loadDef)
        {
            if (loadDef)
                LoadDefVal();
        }

        private void LoadDefVal()
        {
            this.publishDate = Convert.ToInt32("0");
            this.createTime = Convert.ToInt32("0");
            this.creatorId = Convert.ToInt32("0");
        }

        /// <summary>
        /// Desc:内容
        /// Default:
        /// Nullable:True
        /// </summary>           
        public string content { get; set; }

        /// <summary>
        /// Desc:发布日期
        /// Default:0
        /// Nullable:True
        /// </summary>           
        [SugarColumn(ColumnName = "publish_date")]
        public int? publishDate { get; set; }

        /// <summary>
        /// Desc:创建时间
        /// Default:0
        /// Nullable:True
        /// </summary>           
        [SugarColumn(ColumnName = "create_time")]
        public int? createTime { get; set; }

        /// <summary>
        /// Desc:创建人
        /// Default:0
        /// Nullable:True
        /// </summary>           
        [SugarColumn(ColumnName = "creator_id")]
        public int? creatorId { get; set; }

        /// <summary>
        /// Desc:id
        /// Default:
        /// Nullable:False
        /// </summary>           
        [SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
        public int id { get; set; }

        /// <summary>
        /// Desc:标题
        /// Default:
        /// Nullable:True
        /// </summary>           
        public string title { get; set; }

        #region 扩展属性
                
        private string _createTimeText;
        /// <summary>
        /// 创建时间
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public string createTimeText
        {
            set { _createTimeText = value; }
            get
            {
                if (_createTimeText.IsNullOrEmpty() && createTime.Contains())
                    return _createTimeText = createTime.Value.ToDateTimeStr();

                return _createTimeText;
            }
        }

        /// <summary>
        /// 创建人
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public string creatorName { set; get; } = string.Empty;

        private string _publishDateText;
        /// <summary>
        /// 发布时间
        /// </summary>
        [SugarColumn(IsIgnore = true)]
        public string publishDateText
        {
            set { _publishDateText = value; }
            get
            {
                if (_publishDateText.IsNullOrEmpty() && publishDate.Contains())
                {
                    return _publishDateText = publishDate.Value.ToDateTime("yyyyMMdd").ToDateStr();
                }

                return _publishDateText;
            }
        }
        #endregion
    }
}
